package ch.zbw.sysventory.server.control;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import ch.zbw.sysventory.server.model.ComputerScan;
import ch.zbw.sysventory.server.model.Software;
import ch.zbw.sysventory.server.service.ComputerScanService;
import ch.zbw.sysventory.server.service.SoftwareService;

@Component
@Controller
public class SoftwareStatisticController {

	@Autowired
	private ComputerScanService computerScanService;

	@Autowired
	private SoftwareService softwareService;

	@RequestMapping(value = "/softwarestatistic", method = RequestMethod.GET)
	public ModelAndView showSoftwareStatistic(Model model) {
		ComputerScan latestScan = this.computerScanService.getLatestScan();
		List<Software> softwareList = this.softwareService.getAllSwoftwareForLatestScan(latestScan);
		model.addAttribute("amountInstalledSoftware", softwareList.size());
		model.addAttribute("result_list", softwareList);
		return new ModelAndView("softwarestatistic");
	}

}
